package com.ytjj.qmyx.mall.controller.h5;

import com.ytjj.common.api.CommonResult;
import com.ytjj.common.controller.BaseController;
import com.ytjj.qmyx.mall.enums.ActivityTypeEnums;
import com.ytjj.qmyx.mall.model.response.ActivityProductResponse;
import com.ytjj.qmyx.mall.model.response.H5CashScoreIndexResponse;
import com.ytjj.qmyx.mall.service.ActivityService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Collections;
import java.util.List;

@RestController
@RequestMapping("/h5/score")
@Slf4j
public class H5ScoreActivityController extends BaseController {
    @Resource
    private ActivityService activityService;


    @GetMapping("/getProductListByRange")
    public CommonResult getProductListByRange(@RequestParam(value = "pageNum", required = false) Integer pageNum,
                                                    @RequestParam(value = "pageSize", required = false) Integer pageSize,
                                                    @RequestParam(required = false) BigDecimal scoreStart,
                                                    @RequestParam(required = false) BigDecimal scoreEnd) {
        return CommonResult.success(activityService.getActivityListByRange(pageNum, pageSize, ActivityTypeEnums.CASH_SCORE.name(), scoreStart,scoreEnd));
    }

    @GetMapping("/getProductListByPage")
    public CommonResult getProductListByRange(@RequestParam(value = "pageNum", required = false) Integer pageNum,
                                              @RequestParam(value = "pageSize", required = false) Integer pageSize,
                                              @RequestParam(value = "columnId", required = false, defaultValue = "0") Integer columnId,
                                              @RequestParam(value = "flag", required = false, defaultValue = "0") Integer flag,
                                              @RequestParam(value = "jptype", required = false, defaultValue = "0") Integer jptype) {
        if(1==jptype){
            columnId=-2;
        }
        List<ActivityProductResponse> productList =activityService.getActivityList(pageNum, pageSize,ActivityTypeEnums.CASH_SCORE.name(),columnId);
        if(1==flag){//打乱顺序
            Collections.shuffle(productList);
        }
        return CommonResult.success(productList);
    }

    /**
     * 获取栏目组合商品列表(猜你喜欢和排行)
     */
    @GetMapping("/index")
    public CommonResult index(@RequestParam(value = "flag", required = false, defaultValue = "0") Integer flag) {
        H5CashScoreIndexResponse indexResponse=new H5CashScoreIndexResponse();
        List<ActivityProductResponse> firstProductList=activityService.getActivityList(1, 80,ActivityTypeEnums.CASH_SCORE.name(),100);
        List<ActivityProductResponse> secondProductList=activityService.getActivityList(1, 10,ActivityTypeEnums.CASH_SCORE.name(),99);
        if(1==flag){//打乱顺序
            Collections.shuffle(firstProductList);
            Collections.shuffle(secondProductList);
        }
        indexResponse.setFirstProductList(firstProductList);
        indexResponse.setSecondProductList(secondProductList);
        return CommonResult.success(indexResponse);
    }
    @GetMapping("/getUsedScore")
    public CommonResult getUsedScore() {
        BigDecimal usedScore=activityService.queryH5TotalUsedScore();
        if(null==usedScore){
            usedScore=BigDecimal.ZERO;
        }
        return CommonResult.success(usedScore);
    }
}
